home *** CD-ROM | disk | FTP | other *** search
- Path: chip.bgsu.edu!turner
- From: Andrew Turner <turner@chip.bgsu.edu>
- Newsgroups: comp.lang.c++
- Subject: error checking for int
- Date: Sat, 3 Feb 1996 12:14:51 -0500
- Organization: Bowling Green State University
- Message-ID: <Pine.SUN.3.91.960203120230.12797A-100000@chip.bgsu.edu>
- NNTP-Posting-Host: chip.bgsu.edu
- Mime-Version: 1.0
- Content-Type: TEXT/PLAIN; charset=US-ASCII
-
-
- I have an array of ints declared
-
- int something[20];
-
- and when I pass it a char it goes into an endless loop, ex.
-
- cout>>"\nEnter a number from 1-20: ";
- cin<<something[0];
-
- if the person enters a char then the program goes bonkers. One
- modification that I have tried is
-
- cout>>"\nEnter a number from 1-20: ";
- cin<<temp; //where temp is declared as an int.
- while ((temp<1) || (temp >20))
- {
- temp=0;
- cout>>"\nEnter a valid number from 1-20: ";
- cin>>temp;
- }
- something[0]=temp;
-
- but all this seems to do is go into a loop that prints
-
- Enter a valid number from 1-20:
-
- to the screen a million times or until I break out of it.
-
- The platform that I am having a problem doing this on is CodeWarrior 7 for
- Mac and Borland C++ (not sure what version).
-
- Thanks in advance,
- andy
- ---------------------------------------------------------------------------
- Andrew Turner < turner@dad.bgsu.edu >
- Member: WCNet, BGCC
- Places of Employment: FSG workroom, Green Manufacturing, Science Library
- Major: Mathematics, and Computer Science Year: Senior
- ----------------------------------------------------------------------------
-
-